package com.oursnail.jms.producers.Impl;

import com.oursnail.jms.producers.ProducerServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.core.MessageCreator;

import javax.annotation.Resource;
import javax.jms.*;

/**
 * Created By XJL On 2017/11/5
 */
public class ProducerServerImpl implements ProducerServer {
    @Autowired
    JmsTemplate jmsTemplate;
    @Resource(name="queueDestination")
    Destination destination;
    public void sendMessage(final String message) {
        jmsTemplate.send(destination, new MessageCreator() {
           //创建一个消息
            public Message createMessage(Session session) throws JMSException {
                TextMessage textMessage = session.createTextMessage(message);

                return textMessage;
            }

        });
        System.out.println("消息发送--"+message);

    }
}
